package com.briup.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.bean.Slideshow;
import com.briup.service.ISlideshowService;
import com.briup.util.Result;
import com.briup.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author syh
 * @since 2024-09-10
 */
@Api(tags = "轮播图管理")
@RestController
@RequestMapping("/slideshow")
public class SlideshowController {
    @Autowired
    private ISlideshowService service;
    @ApiOperation(value="条件多分页查询轮播图")
    @GetMapping("/query")
    public Result findByPage(@RequestParam(required = true) Integer pageNum,
                             @RequestParam(required = true) Integer pageSize,
                              String desc,String status){
        IPage<Slideshow> page = service.findByPage(pageNum, pageSize, desc, status);
        return ResultUtil.success(page);
    }

    @ApiOperation(value="查询所有启用的轮播图")
    @GetMapping("/queryAllEnable")
    public Result findAll(){
       List<Slideshow> list = service.findAll();
        return ResultUtil.success(list);
    }

    @ApiOperation(value="根据id查询轮播图信息")
    @GetMapping("queryById/{id}")
    public Result findById(String id){
        Slideshow slideshow = service.findById(id);
        return ResultUtil.success(slideshow);
    }

    @ApiOperation(value="根据编号删除轮播图")
    @DeleteMapping("/deleteById/{hId}")
    public Result deleteById(String id){
        service.deleteByBatch(id);
        return ResultUtil.success();
    }

    @ApiOperation(value="新增或更新轮播图")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Slideshow slideshow){
        service.saveOrUpdate(slideshow);
        return ResultUtil.success();
    }
}
